package m2;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @Author wy
 * @Date 2021/3/2 9:51
 * @Version 1.0
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");
        Connection con = f.newConnection();
        //后面与服务器进行通信 都是用这个通信通道来进行
        Channel c = con.createChannel();

        c.queueDeclare("helloworld",true,false,false,null);

        while(true){
            System.out.println("输入信息:");
            String s = new Scanner(System.in).nextLine();
            c.basicPublish("","helloworld", MessageProperties.PERSISTENT_TEXT_PLAIN,s.getBytes());
        }
    }

}
